package easy

import "workspace/node"

func DiameterOfBinaryTree(root *node.TreeNode) int {
	ans := 1
	var dfs func(*node.TreeNode) int
	dfs = func(node *node.TreeNode) int {
		if node == nil {
			return 0
		}
		left := dfs(node.Left)
		right := dfs(node.Right)
		ans = max(ans, left+right+1)
		return max(left, right) + 1
	}
	dfs(root)
	return ans - 1
}
